using UnityEngine;
using System.Collections;

public class Plane : MonoBehaviour {
	
	public static int MOUSE_MID_CLICK = 2;
	
	private float mouseDownReferenceX = 0, mouseDownReferenceY = 0;
	Transform rotPoint;
	
	void Awake () {
		
		rotPoint = transform.FindChild("RotPoint");
	}
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

	
		// Moment unique lors de l appui sur clique droit
		if(Input.GetMouseButtonDown(MOUSE_MID_CLICK)) {
			mouseDownReferenceX = Input.mousePosition.x;
			mouseDownReferenceY = Input.mousePosition.y;
//			Debug.Log("GetMouseButtonDown : Input.mousePosition.x :" + mouseDownReferenceX);
		}
	
		// Toujours appelé lorsque clique droit est préssé:
		if(Input.GetMouseButton(MOUSE_MID_CLICK)) {

			float deltaMouseDownReferenceX = Input.mousePosition.x - mouseDownReferenceX;
			float deltaMouseDownReferenceY = Input.mousePosition.y - mouseDownReferenceY;
//			transform.Rotate(new Vector3(0, -deltaMouseDownReferenceX, 0) * Time.deltaTime);
			transform.RotateAround(rotPoint.position, Vector3.up, -deltaMouseDownReferenceX * Time.deltaTime);
			
			
			//if(transform.rotation.x > -1)
//			transform.RotateAround(rotPoint.position, Vector3.right, -deltaMouseDownReferenceY * Time.deltaTime);
		}
	
		// Moment unique lors du "release" du clique droit
		if(Input.GetMouseButtonUp(MOUSE_MID_CLICK)) {
//			Debug.Log("GetMouseButtonUp");
		
		}
	
	
		/*
		if(Input.GetMouseButton(1)) {
			Debug.Log("mouse x" + Input.mousePosition.x +  Input.acceleration.x);
		}*/
	
//		Debug.Log("mouse x" + Input.mousePosition.x);
	
//		transform.Rotate(new Vector3(0, 1, 0));
	}
}
